package com.woniuxy.ptapp.app.controller;
import com.woniuxy.commons.util.BeanCopyUtil;
import com.woniuxy.commons.util.Result;
import com.woniuxy.ptapp.client.CommentClient;
import com.woniuxy.ptapp.client.param.CommentParam;
import com.woniuxy.ptapp.client.param.ShowEvaluationParam;
import com.woniuxy.ptapp.common.exception.ParamException;
import com.woniuxy.ptapp.service.CommentInfoService;
import com.woniuxy.ptapp.service.dto.CommentDto;
import com.woniuxy.ptapp.service.dto.ShowEvaluationDto;
import com.woniuxy.relation.client.AnnouncementClient;
import com.woniuxy.relation.client.form.SendAnnouncementForm;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 评价信息表 前端控制器
 * </p>
 *
 * @author wangdong
 * @since 2022-07-30
 */
@RestController
public class CommentInfoController implements CommentClient {

    @Resource
    CommentInfoService commentInfoService;

    @Resource
    AnnouncementClient announcementClient;
    @Override
    public Result appraise(CommentParam commentParam) {
        CommentDto commentDto = BeanCopyUtil.copyObject(commentParam, CommentDto.class);
        commentInfoService.appraise(commentDto);
        return Result.getInstance().setMsg("评价成功").setCode(200);
    }

    @Override
    public Result reply(Integer classesOrderId, String reply) {
        if(null==classesOrderId||classesOrderId<=0||reply==""||reply==null){
            throw new ParamException();
        }
        commentInfoService.reply(classesOrderId,reply);

        return Result.getInstance().setMsg("评价回复成功").setCode(200);
    }

    @Override
    public Result<List<ShowEvaluationParam>> showEvaluation() {
        List<ShowEvaluationDto> evaluationDtos = commentInfoService.showEvaluation();
        List<ShowEvaluationParam> showEvaluationParams = BeanCopyUtil.copyList(evaluationDtos, ShowEvaluationParam.class);
        return Result.getInstanceList(ShowEvaluationParam.class).setCode(200).setMsg("查询订单评价成功").setData(showEvaluationParams);
    }

    @Override
    public String test() {
        SendAnnouncementForm sendAnnouncementForm = new SendAnnouncementForm();
        sendAnnouncementForm.setAcceptAccountId("1");
        sendAnnouncementForm.setContent("测试");
        Result result = announcementClient.sendAnnouncement(sendAnnouncementForm);
        System.out.println(result);
        return "success";
    }
}

